import { MONITOR_REPORT_URL, PROJECT_ID, USER_ID } from "./constants.js";
const cacheData = [];
export const lazyReport = (data) => {
  const monitorReportUrl = window[MONITOR_REPORT_URL];
  const projectId = window[PROJECT_ID];
  const userId = window[USER_ID];
  cacheData.push({ ...data, projectId, userId });
  if (cacheData.length == 1) {
    const list = cacheData.splice(0, 1);
    // 做兼容性处理
    if (navigator.sendBeacon) {
      const formData = new FormData();
      formData.append("data", JSON.stringify(list));
      navigator.sendBeacon(monitorReportUrl, formData);
    } else {
      const img = new Image();
      img.src = `${monitorReportUrl}?log=${JSON.stringify(list)}`;
    }
  }
};
export const pageCloseReport = () => {
  const monitorReportUrl = window[MONITOR_REPORT_URL];
};
export default { lazyReport, pageCloseReport };
